
package com.bj58.disconf.web.service.config.service.impl;

import java.util.Date;

import org.springframework.stereotype.Service;

import com.bj58.disconf.web.common.constant.DataFormatConstants;
import com.bj58.disconf.web.service.config.ConfigHistoryDaoImpl;
import com.bj58.disconf.web.service.config.bo.ConfigHistory;
import com.bj58.disconf.web.service.config.service.ConfigHistoryMgr;
import com.bj58.disconf.web.service.user.dto.Visitor;
import com.bj58.disconf.web.utils.GuiceDI;
import com.bj58.ub.common.commons.ThreadContext;
import com.github.knightliao.apollo.utils.time.DateUtils;

/**
 * Created by knightliao on 15/12/25.
 */
@Service
public class ConfigHistoryMgrImpl implements ConfigHistoryMgr {

    @Override
    public void createOne(Long configId, String oldValue, String newValue) {

        ConfigHistory configHistory = new ConfigHistory();

        configHistory.setConfigid(configId);
        configHistory.setOldvalue(oldValue);
        configHistory.setNewvalue(newValue);

        Visitor visitor = ThreadContext.getSessionVisitor();
        if (visitor != null) {
            configHistory.setUpdateBy(visitor.getLoginUserId());
        }

        String curTime = DateUtils.format(new Date(), DataFormatConstants.COMMON_TIME_FORMAT);
        configHistory.setCreatetime(curTime);

        GuiceDI.getInstance(ConfigHistoryDaoImpl.class).insert(configHistory);
    }
}
